<template>
	<view> 
		<block v-if="isHasDataFlag">
			<view class="ansQueList"
				v-for="(item,index) in ansQueList"
				:key="index"
				@tap="goQueDet(item.id,index)"
			>
				<view class="puber hasFlex">
					<view class="headImg">
						<image class="samePar" v-if="item.userPortrait == ''" src="../../../static/images/defHead.png"></image>
						<image class="samePar" v-else :src="getCloudFilePath(item.userPortrait)"></image>
					</view>
					<view class="usename">{{item.realName}}</view>
				</view>
				<view class="ansQuesTit multiEllip clamp2">{{item.askTitle}}</view>
				<view class="queCon">
					<view class="inner multiEllip clamp4">
						<rich-text :nodes="item.askContent"></rich-text>
					</view>
				</view>
				<view class="queBot spaceBet">
					<view class="time">{{item.addTime}}</view>
					<view class="right hasFlex">
						<view class="ly hasFlex">
							<text class="iconfont icon-message"></text>
							<text>{{item.plNum}}</text>
						</view>
						<view class="favor hasFlex">
							<text class="iconfont icon-favor" v-if="item.dzTag == 0"></text>
							<text class="iconfont icon-favor spec" v-if="item.dzTag == 1"></text>
							<text>{{item.upNum}}</text>
						</view>
					</view>
				</view>
			</view>
			<loading-view :loading="loading"></loading-view>
		</block>
		<block v-else-if="isHasDataFlag == false">
			<no-data></no-data> 
		</block>
		<view class="iconfont icon-bianji" @tap="goPubQue"></view>
	</view>
</template>

<script>
	import { getAnsQueList } from '@/api/ansQue/index'
	export default {
		data(){
			return{
				isHasDataFlag:null,
				ansQueList:[],
				nowPage:1,
				loading:false
			}
		},
		onLoad(){
			this.loadMyAnsQueList();
		},
		onShow(){
			if(this.isRefreshFlag){
				this.initParams();
			}
		},
		onHide(){
			this.isRefreshFlag = false;
		},
		onPullDownRefresh : function(){
			this.initParams();
			uni.stopPullDownRefresh();
		},
		onReachBottom : function(){
			if( !this.loading ){
				this.loadMyAnsQueList();
			}
		},
		methods:{
			loadMyAnsQueList(){
				let { nowPage,ansQueList } = this;
				this.loading = true;
				var field = { opt:this.dealStatusVal,page:this.nowPage,limit:this.limit };
				getAnsQueList(field).then(res=>{
					//console.log(res)
					nowPage += 1;
					ansQueList.push( ...res.data.datas );
					this.ansQueList = ansQueList;
					this.nowPage = nowPage;
					this.loading = false;
					this.isHasDataFlag = true;
				}).catch(err=>{
					console.log(err)
					this.loading = false;
					this.isHasDataFlag=false;
				});
			},
			initParams(){
				this.nowPage = 1;
				this.loading = false;
				this.ansQueList = [];
				this.loadMyAnsQueList();
			},
			goQueDet(id,index){
				uni.navigateTo({
					url:'../queDet/queDet?queId=' + id + '&currIndex=' + index + '&fromPage=ansQueList'
				})
			},
			goPubQue(){
				if(uni.getStorageSync('userIdZz')){
					uni.navigateTo({
						url:'../pubQue/pubQue'
					})
				}else{
					uni.navigateTo({
						url:'/pages/login/login?loginNum=0'
					})
				}
			}
		}
	}
</script>
<style lang="scss">
	page{
		background: $pss-bg-primary;
	}
</style>
<style lang='scss' scoped>
	@import '@/static/scss/ansQueList.scss';
</style>